/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.credsoft.copcred.model.vo;

import br.gov.caixa.gisutsa.framework.tapiocaframework.persistencia.AbstractEntity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

/**
 *
 * @author Sales
 * @since 2009-07-16
 */
@Entity
@Table(name = "menu")
public class Menu extends AbstractEntity {

    private static final long serialVersionUID = -8828292009190370914L;
    private Long id;
    private int version;
    private String nome;
    private int ordem;
    private String link;
    private Menu menuDependente;
    private List<Menu> menusVinculados;
    private List<Perfil> perfis;

    public Menu() {
    }

    public Menu(Long id) {
        this.id = id;
    }

    public Menu(Long id, String nome, int ordem, String link, Menu menuDependente) {
        this.id = id;
        this.nome = nome;
        this.ordem = ordem;
        this.link = link;
        this.menuDependente = menuDependente;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "menu_id", nullable = false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Version
    @Column(name = "versao", nullable = false)
    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    @Column(name = "nome", nullable = false, length = 30)
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    @Column(name = "ordem", nullable = false)
    public int getOrdem() {
        return ordem;
    }

    public void setOrdem(int ordem) {
        this.ordem = ordem;
    }

    @Column(name = "link", nullable = false, length = 50)
    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    @ManyToOne(targetEntity = Menu.class, fetch = FetchType.EAGER)
    @JoinColumn(name = "menu_dependente", nullable = true)
    public Menu getMenuDependente() {
        return menuDependente;
    }

    public void setMenuDependente(Menu menuDependente) {
        this.menuDependente = menuDependente;
    }

    @ManyToMany(targetEntity = Perfil.class, mappedBy="menus")
    public List<Perfil> getPerfis() {
        return perfis;
    }

    public void setPerfis(List<Perfil> perfis) {
        this.perfis = perfis;
    }

    @OneToMany(targetEntity = Menu.class, mappedBy = "menuDependente")
    public List<Menu> getMenusVinculados() {
        return menusVinculados;
    }

    public void setMenusVinculados(List<Menu> menusVinculados) {
        this.menusVinculados = menusVinculados;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Menu other = (Menu) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
}
